package com.hnkywl.sts.service.tjbb;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.tjbb.FkbbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: SDE09
 * Date: 13-9-28
 * Time: 下午5:13
 * To change this template use File | Settings | File Templates.
 */
@Service
public class FkbbService {
    private FkbbDao fkbbDao;

    public String fkbbList(Date enddt) {
        List<Map> list = fkbbDao.findfkbbList(enddt);
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        String json = gson.toJson(list);
        if (list.size() != 0) {
            Double kyjs = 0d;
            Double kysl = 0d;
            Double htjs = 0d;
            Double htsl = 0d;
            Double wckjs = 0d;
            Double wcksl = 0d;
            Double kgdjs = 0d;
            Double kgdsl = 0d;
            Double gdjs = 0d;
            Double gdsl = 0d;
            for (Map map : list) {
                kyjs += Double.valueOf((map.get("KY_JS") == null ? 0d : map.get("KY_JS")).toString());
                kysl += Double.valueOf((map.get("KY_SL") == null ? 0d : map.get("KY_SL")).toString());
                htjs += Double.valueOf((map.get("HT_JS") == null ? 0d : map.get("HT_JS")).toString());
                htsl += Double.valueOf((map.get("HT_SL") == null ? 0d : map.get("HT_SL")).toString());
                wckjs += Double.valueOf((map.get("WCK_JS") == null ? 0d : map.get("WCK_JS")).toString());
                wcksl += Double.valueOf((map.get("WCK_SL") == null ? 0d : map.get("WCK_SL")).toString());
                kgdjs += Double.valueOf((map.get("KGD_JS") == null ? 0d : map.get("KGD_JS")).toString());
                kgdsl += Double.valueOf((map.get("KGD_SL") == null ? 0d : map.get("KGD_SL")).toString());
                gdjs += Double.valueOf((map.get("GD_JS") == null ? 0d : map.get("GD_JS")).toString());
                gdsl += Double.valueOf((map.get("GD_SL") == null ? 0d : map.get("GD_SL")).toString());
            }
            return "{\"rows\":" + json + ",\"footer\":[{\"CK_MC\":\"合计:\",\"KY_JS\":" + kyjs + ",\"KY_SL\":" + kysl + ",\"HT_JS\":" + htjs + ",\"HT_SL\":" + htsl + ",\"WCK_JS\":" + wckjs + ",\"WCK_SL\":" + wcksl + ",\"KGD_JS\":" + kgdjs + ",\"KGD_SL\":" + kgdsl + ",\"GD_JS\":" + gdjs + ",\"GD_SL\":" + gdsl + " }]}";
        } else {
            return "{\"rows\":" + json + "}";
        }

    }


    @Autowired
    public void setFkbbDao(FkbbDao fkbbDao) {
        this.fkbbDao = fkbbDao;
    }
}
